class Solution {
public:
    int searchInsert(vector<int>& nums, int t) {
        int sz=nums.size();
        int l=0;
        int r=sz-1;
        if(nums[r]<t)
            return r+1;
        while(l<=r)
        {
            int mid=l+(r-l)/2;
            if(nums[mid]>t)
                r=mid-1;
            else if(nums[mid]<t)
                l=mid+1;
            else
                return mid;
        }
        return l;
    }
};
